package com.xindacloud.sms.adapter.service.business.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.xindacloud.sms.adapter.dao.SmsAgentRouteMapper;
import com.xindacloud.sms.adapter.entity.SmsAgentRoute;
import com.xindacloud.sms.adapter.exception.ServiceException;
import com.xindacloud.sms.adapter.service.business.ISmsAgentRouteService;
import com.xindacloud.sms.adapter.utils.UnionResultHelp;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.Optional;


@Slf4j
@Service
public class SmsAgentRouteServiceImpl extends ServiceImpl<SmsAgentRouteMapper, SmsAgentRoute> implements ISmsAgentRouteService {


    @Override
    public SmsAgentRoute saveSmsRoute(SmsAgentRoute smsAgentRoute) {
        save(smsAgentRoute);
        return smsAgentRoute;
    }

    @Override
    public void updateSmsRoute(SmsAgentRoute smsAgentRoute) {
        lambdaUpdate()
                .set(SmsAgentRoute::getRouteService, smsAgentRoute.getRouteService())
                .eq(SmsAgentRoute::getRouteId, smsAgentRoute.getRouteId())
                .update();
    }

    @Override
    public SmsAgentRoute querySmsRouteById(Integer routeId) {
        final SmsAgentRoute smsAgentRoute = lambdaQuery()
                .eq(SmsAgentRoute::getRouteId, routeId)
                .one();
        return Optional.ofNullable(smsAgentRoute)
                .orElseThrow(() -> new ServiceException("没有找到路由服务.", UnionResultHelp.StatusEnum.NotFound.code()));
    }
}
